#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Purpose: Fields classes that can be associated to a Node
# Created: 01/22/2009
# $Id $
# Copyright (c) 2008,2009 by University College London
# Authors: 
# Didrik Pinte --<dpinte@dipole-consulting.com>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with HydroPlatform for details.

import unittest

from enthought.traits.api import HasTraits, Instance
from enthought.traits.ui.api import View, Item
from enthought.chaco.api import Plot, ArrayPlotData
from enthought.chaco.tools.api import PanTool, ZoomTool, DataLabelTool
from enthought.chaco.shell import *

from enthought.enable.component_editor import ComponentEditor

from numpy import linspace, sin, pi


class LinePlot(HasTraits):
    
    plot = Instance(Plot)
    traits_view = View(
        Item('plot',editor=ComponentEditor(), show_label=False),
        width=500, height=500, resizable=True, title="Chaco Plot")

    def __init__(self):
        super(LinePlot, self).__init__()
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)
        plot = Plot(plotdata)
        plot.plot(("x", "y"), type="line", color="blue")
        plot.title = "sin(x) * x^3"
        plot.tools.append(PanTool(plot))
        plot.overlays.append(ZoomTool(plot, tool_mode="box", always_on=False))
        self.plot = plot



class TestChacoWin32(unittest.TestCase):
    
    def test_zoom1(self):
        '''
        works fine on win32
        '''
        x = linspace(-2*pi, 2*pi, 100)
        y = sin(x)

        plot(x, y, "r-")
        title("First plot")
        ytitle("sin(x)")
        show()

    def test_zoom2(self):
        '''
        Mouse wheel does not work !
        '''
        a = LinePlot()
        a.configure_traits()
        
if __name__ == '__main__':
    unittest.main()